package com.yu.mall.util;

import com.github.pagehelper.PageInfo;
import com.yu.mall.constants.Constants;
import com.yu.mall.vo.PageResultVO;
import com.yu.mall.vo.ResultVO;
import com.yu.mall.vo.TreeResultVO;
import com.yu.mall.vo.TreeVO;

import java.util.List;

public class ResultUtils {

    public static ResultVO success(Object object) {
        ResultVO result = new ResultVO();
        result.setCode(Constants.SUCCESS_CODE);
        result.setMsg("成功");
        result.setData(object);
        return result;
    }

    public static ResultVO success() {
        return success(null);
    }

    public static ResultVO error(String code, String msg, Object data) {
        ResultVO result = new ResultVO();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static ResultVO error(String code,String msg) {
        return error(code,msg,null);
    }

    public static ResultVO error(String msg) {
        return error(Constants.SYSTEM_ERROR_CODE,msg);
    }


    public static PageResultVO page(PageInfo page) {
        PageResultVO result = new PageResultVO();
        result.setCode(Constants.SUCCESS_CODE);
        result.setMsg("成功");
        result.setData(page.getList());
        result.setTotal(page.getTotal());
        return result;
    }

    public static TreeResultVO tree(List<TreeVO> vo, List<Integer> checked) {
        TreeResultVO result = new TreeResultVO();
        result.setCode(Constants.SUCCESS_CODE);
        result.setMsg("成功");
        result.setData(vo);
        result.setChecked(checked);
        return result;
    }

}
